import axios from 'axios'
import Notify from '@/components/prompt/prompt.js'

const request = axios.create({
  baseURL: process.env.VUE_APP_SERVE,
  timeout: 10 * 5000
})
// 响应拦截器
request.interceptors.request.use(config => {
  const token = localStorage.getItem('token')
  token && (config.headers.Authorization = token)
  return config
}, error => {
  console.log('请求拦截器 - 发生错误:', error)
  return Promise.reject(error)
})
// 响应拦截器
request.interceptors.response.use(response => {
  if (response.data.code === 200) {
    Notify.success(response.data.message)
    return response.data
  } else {
    return Promise.reject(response.data.message)
  }
}, error => {
  return Promise.reject(error);
});
export default request